package com.potenza.training.reply.controller;

import com.potenza.training.reply.entity.SubjectEntity;
import com.potenza.training.reply.entity.SubjectReplyEntity;
import com.potenza.training.reply.service.SubjectReplyService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 题目和答辩室的中间表
 *
 * @author lihonggang
 * @email lihonggang@gmail.com
 * @date 2021-07-22 15:57:41
 */
@RestController
@RequestMapping("reply/subjectreply")
public class SubjectReplyController {
    @Autowired
    private SubjectReplyService subjectReplyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("reply:subjectreply:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = subjectReplyService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{tbSujectId}")
    @RequiresPermissions("reply:subjectreply:info")
    public R info(@PathVariable("tbSujectId") Long tbSujectId){
		SubjectReplyEntity subjectReply = subjectReplyService.getById(tbSujectId);

        return R.ok().put("subjectReply", subjectReply);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("reply:subjectreply:save")
    public R save(@RequestBody SubjectReplyEntity subjectReply){
		subjectReplyService.save(subjectReply);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("reply:subjectreply:update")
    public R update(@RequestBody SubjectReplyEntity subjectReply){
		subjectReplyService.updateById(subjectReply);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("reply:subjectreply:delete")
    public R delete(@RequestBody Long[] tbSujectIds){
		subjectReplyService.removeByIds(Arrays.asList(tbSujectIds));

        return R.ok();
    }

    /**
     * 创建中间表
     */
    @RequestMapping("/insert/{id}/{ids}")
    @RequiresPermissions("reply:subjectreply:insert")
    public R insert(@PathVariable int id,@PathVariable int[] ids){
        subjectReplyService.insert(id,ids);

        return R.ok();
    }


    @GetMapping("/findbygroupid/{gid}")
    @RequiresPermissions("reply:subjectreply:findbygroupid")
    public R findByGroupId(@PathVariable Long gid){
        List<SubjectEntity> subjectEntityList = subjectReplyService.findByGroupId(gid);

        return R.ok().put("data", subjectEntityList);
    }
}
